<?php
namespace App\Controllers\Product\Page;
use \App\Models\Goods\Goods;
use \App\Models\Goods\GoodsAffiliate;
use \App\Models\Experience\ExpGoods;
/**
*	体验产品详情页
*
*/
class ExpressDel extends  \App\Libs\Base\BaseTwigAction 
{
    protected function beforeRun() {
        parent::beforeRun();
	//	 $this->needLogin = TRUE;
    }
	
	public function execute() {
		$eid = (int)$this->request->get("gid");
		$lat = $this->request->get("latitude");
        	$lon = $this->request->get("longitude");
		if( empty($lat) or empty( $lon ) ){
                        $lat = '1';
                        $lon = '1';
                }
		//$eid = $this->request->get('eid');
            	$eDetail = ExpGoods::find([
                	'conditions' => 'id = ?1',
                	'columns' => 'id as eid,num as havenum,gid,end_time',
                	'bind' => [1 => $eid]
            	])->toArray();

		$gid = $eDetail['gid'];
		$goods = Goods::find(array(
			'id=:gid:',
			'bind'=>array('gid'=>$gid)
		));
		$goodsAffiliate = GoodsAffiliate::find(array( 
			'gid=:gid:',
			'bind'=>array('gid'=>$gid)
		));
		
		//判断是否失效
		$nowTime = date("Y-m-d H:i:s");
		$show = true;
		if( $eDetail['end_time'] < $nowTime ){
			$show = false;
		}
		
		
		
		//\App\Libs\Log\Logger::info("goods_info", json_encode($goods));
		$this->addParam('gid',$eid);
		$this->addParam('lat',$lat);
		$this->addParam('show',$show);
                $this->addParam('lon',$lon);
		$this->addParam('goods',$goods);
		$this->addParam('goodsAffiliate',$goodsAffiliate);
		return parent::execute();
	}
}
